%%%%%%%% Credits

The following files (data and code)

- SgnQ.m

in this folder are borrowed and modified from the open-source repository associated with:

Pengsheng Ji, Jiashun Jin, Zheng Tracy Ke, and Wanshan Li. Co-citation and co-authorship
networks for statisticians (with discussions). J. Bus. Econ. Statist., 40(2), 2022.

########## Functions

1. SgnQ(A): computes SgnQ pvalues, unstandardized value, and standardized value on input adjacency matrix A

2. true_calibrate_scan: 
Inputs -  
    n  %graph size 
    N  %subset size
    alpha %null parameter, edge density under alternative
    B  % number of subsets
    M % number of samples
    kappa  %target level

Outputs the 1- kappa empirical quantile of the empirical distribution of the (true) scan statistic of M repetitions drawn from a null SBM with parameter alpha. 

3. oracle_power_scan:
Inputs -  
    n  %graph size 
    N  %subset size
    alpha %null parameter, edge density under alternative
    B  % number of subsets
    M_power % number of samples
    kappa  %target level
    threshold 
    num_a_samples

 Outputs power curve values for oracle scan with the given threshold. To compute the power curve, a total of M_power alternative samples are drawn from SBM with edge density alpha for each value of a (the small community probability) larger than alpha. 

 4. true_scan: Given an adjacency matrix A and subset parameter N, this function computes the exact value of the true scan statistic.

 ########## Script

 oracle_scan_vs_SgnQ: 
 Parameters - N_vec, n_vec: N values and n values that will be looped over
 Output - Figure with power curve of Scan and SgnQ for each (n, N) value in n_vec x N_vec, along with theoretical phase transition markers


 ########### Tricks

 oracle_scan_vs_SgnQ also exports the threshold values computed by calibrate_scan as a n_vec x N_vec table. Thus further power computations with the same parameter settings can skip the (expensive) calibration step by first importing the corresponding saved table of thresholds.
